package com.demo.chapter12date;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.time.temporal.ChronoUnit;

//以秒或纳秒来衡量两个时间的长短
public class DurationDemo {

	public static void demo(){
		LocalTime time = LocalTime.of(13, 45, 20);
		Duration d1 = Duration.between(LocalTime.of(13, 45, 10), time);

		Instant instant = Instant.ofEpochSecond(3);
		Instant now = Instant.now();
        Duration d2 = Duration.between(instant, now);

        LocalDateTime datetime = LocalDateTime.of(2016, Month.MARCH, 18, 13, 45, 20);
        LocalDateTime datetime2 = LocalDateTime.of(2016, Month.MARCH, 18, 13, 45, 25);
        Duration d3 = Duration.between(datetime, datetime2);

        System.out.println(d1.getSeconds());
        System.out.println(d2.getSeconds());
        System.out.println(d3.getSeconds());

        //创建3分钟的时间
        Duration d4 = Duration.ofMinutes(3);
        System.out.println(d4.getSeconds());
        Duration d5 = Duration.of(3, ChronoUnit.MINUTES);
        System.out.println(d5.getSeconds());
	}

	public static void main(String[] args) {
		demo();
	}

}
